﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using wathammer40kListBuilder.View;

namespace wathammer40kListBuilder
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static MainWindow Windows { get; private set; }
        public MainWindow()
        {
            InitializeComponent();
            MainWindow.Windows = this;
            System.Data.Entity.Database.SetInitializer<wh40klbModel.WarhammerContext>(null);

            AddTaB(new AdminArmy(),"Armée");
        }
        private void newArmyMenuItem_Click(object sender, RoutedEventArgs e)
        {
            AddTaB(new NewArmyPanel(), "nouvelle Armée");
        }

        public void AddTaB(UserControl uc,string tabName)
        {
            TabItem tb = new TabItem();
            tb.Header = tabName;
            tb.Content = uc;

            mainWindowTabControl.Items.Add(tb);
            mainWindowTabControl.SelectedIndex = mainWindowTabControl.Items.Count - 1;
        }

        public void CloseSelectedTab()
        {
            TabItem tb = mainWindowTabControl.SelectedItem as TabItem;
            if (tb == null) return;
            mainWindowTabControl.Items.Remove(tb);
            tb.Content = null;
            tb = null;
        }

        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            CloseSelectedTab();
        }

        private void MenuItem_Click_2(object sender, RoutedEventArgs e)
        {
            AddTaB(new AdminArmy(),"Armée");
        }

    }
}
